package org.belkodevelop.security;

import java.io.Serializable;
import java.util.Collection;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class SimpleAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
    private static final long serialVersionUID = 1L;
    private Object principal;
    private int keyHash;

    public SimpleAuthenticationToken(String key, UserDetails user) {
        super(user.getAuthorities());

        if ((key == null) || ("".equals(key)) || (user == null)) {
            throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
        }
        
        if (user.getAuthorities().isEmpty()) {
            throw new IllegalArgumentException("Cannot user.getAuthorities() is null or empty");
        }

        this.keyHash = key.hashCode();
        this.principal = user;
        setAuthenticated(true);
    }
    
    @Override
    public Object getCredentials() {
        return "";
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }
    
    public int getKeyHash() {
        return this.keyHash;
    }
}
